﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel.DomainServices.Server;
using Agility.Web.Models.DomainModel;
using Agility.Web.Repositories.EntityFramework;

namespace Agility.Web.Services
{
    public class RequirementsManagementServiceFactory : IDomainServiceFactory
    {
        public DomainService CreateDomainService(Type domainServiceType, DomainServiceContext context)
        {
            DomainService domainService;
            if (typeof(RequirementsManagementService) == domainServiceType)
            {
                AgilityRequirementsModelEntities requirements = new AgilityRequirementsModelEntities();
                domainService = new RequirementsManagementService(new EpicRepository(requirements));
            }
            else
                domainService = (DomainService)Activator.CreateInstance(domainServiceType);
            domainService.Initialize(context);
            return domainService;
        }

        public void ReleaseDomainService(DomainService domainService)
        {
            domainService.Dispose();
        }
    }
}